package com.xc.h05.service.wutao.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.Charge;
import com.xc.h05.entity.Consult;
import com.xc.h05.entity.Privatemessage;
import com.xc.h05.mapper.ConsultMapper;
import com.xc.h05.mapper.PrivatemessageMapper;
import com.xc.h05.service.wutao.PrivatemessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class PrivatemessageServiceImpl implements PrivatemessageService {
    @Autowired
    private PrivatemessageMapper privatemessageMapper;

    @Autowired
    private ConsultMapper consultMapper;


    @Override
    public int add(Privatemessage privatemessage) {
        int add = privatemessageMapper.add(privatemessage);
        return add;
    }

    @Override
    public int delete(Long id) {
        int delete = privatemessageMapper.delete(id);
        return delete;
    }

    @Override
    public int update(Privatemessage privatemessage) {
        int update = privatemessageMapper.update(privatemessage);
        return update;
    }

    @Override
    public List<Privatemessage> findAll() {
        List<Privatemessage> list = privatemessageMapper.findAll();
        return list;
    }

    @Override
    public PageInfo<Privatemessage> findByPage(int pageNum, int pageSize, Privatemessage privatemessage) {
        PageHelper.startPage(pageNum,pageSize);
        List<Privatemessage> list = privatemessageMapper.findByPage(privatemessage);
        for(Privatemessage ca:list){
            Consult consult = consultMapper.findById2(ca.getConsultId());
            ca.setConsult(consult);
        }
        PageInfo<Privatemessage> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int deleteByIds(List<Long> ids2) {
        int i = privatemessageMapper.deleteByIds(ids2);
        return i;
    }

    @Override
    public List<Privatemessage> findByCid(Integer cid) {
        List<Privatemessage> list = privatemessageMapper.findByCid(cid);
        return list;
    }
}
